package com.jtx.miaoah2.Common;

import com.jtx.miaoah2.Mapper.SkGoodsSeckillMapper;
import com.jtx.miaoah2.Model.goods.DO.SkGoodsSeckill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

/**
 * @author 季台星
 * @Date 2023 07 26 17 36
 */
@Service
public class SpringRetryService {
    @Autowired
    private SkGoodsSeckillMapper skGoodsSeckillMapper;



    @Retryable(value = RuntimeException.class,maxAttempts = 5)
    public void decrementStock(){
        SkGoodsSeckill skGoodsSeckill = skGoodsSeckillMapper.selectById(20);
        if (skGoodsSeckill.getStockCount() > 0){
            int loop = skGoodsSeckillMapper.decrementGoodsStock(skGoodsSeckill.getId(),skGoodsSeckill.getGoodsId(),skGoodsSeckill.getVersion());
            if (loop == 0){
                System.out.println("启动重试机制");
                throw new RuntimeException("启用重试机制");
            }
        }
    }
}
